//
//  SZTTabBarButton.m
//  OC-微博
//
//  Created by z先生 on 17/2/8.
//  Copyright © 2017年 SZT. All rights reserved.
//

#define TabbarButtonImageRatio 0.6

#import "SZTTabBarButton.h"

@implementation SZTTabBarButton


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.imageView.contentMode = UIViewContentModeCenter;
        
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        self.titleLabel.font = [UIFont systemFontOfSize:11];
        
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
       
        [self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        
        
    }
    
    return self;
    
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    CGFloat imageW = contentRect.size.width;
    
    CGFloat imageH = contentRect.size.height * TabbarButtonImageRatio;
    
    return  CGRectMake(0, 0, imageW, imageH);
    
}

-(void)setHighlighted:(BOOL)highlighted{
    
}
-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    
    CGFloat titleY = contentRect.size.height * TabbarButtonImageRatio;
    
    CGFloat titleW = contentRect.size.width;
    
    CGFloat titleH = contentRect.size.height * (1-TabbarButtonImageRatio);
    
    return CGRectMake(0, titleY, titleW, titleH);
    
    
}

-(void)setItem:(UITabBarItem *)item{
    
    _item = item;
    
    [self setTitle:item.title forState:UIControlStateNormal];
   
    [self setImage:item.image forState:UIControlStateNormal];
   
    [self setImage:item.selectedImage forState:UIControlStateSelected];

}
@end
